import 'package:flutter/material.dart';
import 'package:kxy_flutter_app/components/loading_widget.dart';

class LoadingDialog {
  BuildContext _context;
  bool _isShow;

  LoadingDialog(BuildContext context) {
    this._context = context;
  }

  void show({String text = '加载中'}) {
    if (_isShow == true) return;
    _isShow = true;
    showDialog(
      context: _context,
      barrierDismissible: true,
      builder: (cxt) {
        return LoadingWidget(text: text);
      },
    );
  }

  void dismiss() async {
    if (_isShow == true) {
      _isShow = false;
      if (Navigator.of(_context).canPop()) {
        Navigator.of(_context).pop();
      }
    }
  }
}
